<template>
	<view class="planting">
		<view class="card u-p-20 u-m-b-30 u-m-r-32" style="float:left;" @click="goDetail(item)" v-for="(item,index) in treeList" :key="index">
			<view class="title u-p-b-10 u-line-1">{{item.name}}</view>
			<view class="u-flex progress">
				<view style="width:60%;">
					<u-line-progress height="16" :show-percent="false" active-color="#3D9E6A" :percent="((item.energy-item.needEnergy)/item.energy)*100"></u-line-progress>
				</view>
				
				<view class="text">{{item.energy}}g</view>
			</view>
			<view v-if="item.type == 1">
				<view class="gray" v-if="item.needEnergy==0">可以种树啦</view>
				<view class="gray" v-else>还差{{item.needEnergy}}g</view>
			</view>
			<view v-else>
				<view class="gray" v-if="item.needEnergy==0">可以守护啦</view>
				<view class="gray" v-else>还差{{item.needEnergy}}g</view>
			</view>
			
			<view class="img u-m-t-20 u-m-b-20"> 
				<u-image :src="$u.http.config.baseUrl+ (item.url&&item.url.url)" width="100%" height="100%" mode="scaleToFill"></u-image>
			</view>
			<view class="u-flex bottom">
				<view class="left u-line-1" style="width:60%;">{{item.sponsor}}</view>
				<view class="right u-line-1" style="width:40%;">
					<u-icon name="map" color="#488EF5"></u-icon>
					<span style="color:#488EF5;">{{item.city === "市辖区" ? item.province : item.city}}</span>
				</view>
			</view>
			
			<view class="complete" v-show="item.claimStatus ===1">已领完</view>
			<view :class="{treeCom: item.claimStatus ===1}"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				treeList: []
			}
		},
		onShow() {
			this.$u.api.forestTree().then(res => {
				res.map(value => {
					value.url = JSON.parse(value.url)[0]
				})
				
				this.treeList = res
			})
		},
		methods: {
			goDetail (item) {
				if(item.claimStatus ===1){
					return;
				}
				this.$u.route('pages/work/apply/loveforest/personal_garden/planting_trees/planting_detail', item)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.planting {
		background-color: #344333;
		height:100vh;
		padding: 20px 0 20px 20px;
		font-size: 12px;
		justify-content: space-between;
		flex-wrap: wrap;
		width:100%;
		overflow: auto;
		.card {
			flex:1;
			width: 320rpx;
			height: 520rpx;
			background: #fff;
			border-radius: 10rpx;
			min-width: 320rpx;
			max-width: 320rpx;
			position:relative;
			.title {
				font-size: 36rpx;
				font-weight: bold;
			}
			.gray{
				color:#999999;
				font-size: 20rpx;
			}
			.progress {
				justify-content: space-between;
				.text{
					color:#333333;
					font-size:28rpx;
					font-weight: 600;
				}
			}
			.img{
				width: 90%;
				height: 290rpx;
				margin: 0 auto;
			}
			.bottom {
				justify-content: space-between;
				.left {
					color: #333;
					font-size: 22rpx;
				}
			}
			.complete{
				position:absolute;
				top:10px;
				right:10px;
				width: 130rpx;
				height:130rpx;
				border-radius: 50%;
				background: #488EF5;
				line-height:130rpx;
				text-align: center;
				color:#fff;
				font-size: 14px;
				transform: rotate(-15deg);
				z-index:200
			}
			.treeCom {
				width:100%;
				height:100%;
				background:#FFFFFF;
				z-index:1000;
				position:absolute;
				top:0;
				left:0;
				opacity:.7;
				border-radius: 6px;
				z-index:100
			}
		}
		
	}
	
</style>
